package com.study.userprofile.dao

import com.study.userprofile.bean.TagInfo
import com.study.userprofile.util.MySqlUtil

object TagInfoDAO {

  def getTagInfoByTaskId(taskId: String): TagInfo = {
    val tagInfoSql: String =
      s"""select id,tag_code,tag_name,
         | parent_tag_id,tag_type,tag_value_type,
         | tag_value_limit,tag_task_id,tag_comment,
         | create_time
         | from tag_info
         | where tag_task_id=$taskId""".stripMargin
    val tagInfoOpt: Option[TagInfo] =
      MySqlUtil.queryOne(tagInfoSql, classOf[TagInfo], true)
    var tagInfo: TagInfo = null;
    if (tagInfoOpt != None) {
      tagInfo = tagInfoOpt.get
    } else {
      throw new RuntimeException("no tag  for task_id  : " + taskId)
    }
    tagInfo
  }

  def getTagInfoList(): List[TagInfo] ={

    val tagListSql="select  tg.id,tag_code,tag_name,parent_tag_id,tag_type,tag_value_type,tag_value_limit,tag_task_id,tag_comment,tg.create_time" +
      " from tag_info tg join task_info tk  on tg.tag_task_id=tk.id  where tk.task_status='1' "
    val tagInfoList: List[TagInfo] = MySqlUtil.queryList(tagListSql, classOf[TagInfo],true)
    tagInfoList
  }
}
